package com.chanyachting.emall.serviceImpl;

import java.util.List;

import com.chanyachting.emall.dao.ChannelDAO;
import com.chanyachting.emall.dao.ProductcategoryDAO;
import com.chanyachting.emall.domain.Company;
import com.chanyachting.emall.domain.Companykeyword;
import com.chanyachting.emall.domain.Productcategory;
import com.chanyachting.emall.service.ProductcategoryService;

public class ProductcategoryServiceImpl implements ProductcategoryService {

	private ProductcategoryDAO pcDao;

	public ProductcategoryServiceImpl(ProductcategoryDAO pcdao) {

		this.pcDao = pcdao;

	}

	public ProductcategoryServiceImpl() {

		this.pcDao = new ProductcategoryDAO();
	}

	public boolean addProductcategory(Productcategory pc) {

		this.pcDao.save(pc);

		return true;
	}

	public boolean delProductcategory(Productcategory pc) {

		this.pcDao.delete(pc);

		return true;
	}

	public List<Productcategory> getAllProductcategory() {

		return this.pcDao.find("from Productcategory");
	}

	public Productcategory getOneProductcategory(Productcategory pc) {

		return (Productcategory) this.pcDao.load(Productcategory.class, pc
				.getId());
	}

	public boolean updateProductcategory(Productcategory pc) {

		return this.pcDao.update(Productcategory.class, pc, pc.getId());
	}

	public boolean updateProductcategoryPri(Productcategory pc) {

		return this.pcDao.update(Productcategory.class, pc, pc.getId());
	}

	public List<Productcategory> getProductcategoryByBusinesscategoryId(
			String businesscategoryId) {

		return this.pcDao.getProductcategoryByBusinesscategoryId(businesscategoryId);
	}
	
	public List<Companykeyword> getCompanyByProductcategoryName(
			String name){
		return this.pcDao.getCompanyByProductcategoryName(name);
	}

	@SuppressWarnings("unchecked")
	public Productcategory getOneProductcategoryById(String id) {
		String sql = "from Productcategory where id = ?";
		
		List<Productcategory> l = this.pcDao.find(sql, new String[]{id});
		
		if (l == null || l.size() != 1) {
			return null;
		}
		return l.get(0);
	}
}
